home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / xevious.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  10KB  |  385 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10.  
  11.  
  12. unsigned char *xevious_fg_videoram,*xevious_fg_colorram;
  13. unsigned char *xevious_bg_videoram,*xevious_bg_colorram;
  14.  
  15. extern unsigned char *spriteram,*spriteram_2,*spriteram_3;
  16. extern size_t spriteram_size;
  17.  
  18. static struct tilemap *fg_tilemap,*bg_tilemap;
  19.  
  20. /* scroll position controller write (CUSTOM 13-1J on seet 7B) */
  21. static int flipscreen;
  22.  
  23.  
  24.  
  25.  
  26. /***************************************************************************
  27.  
  28.   Convert the color PROMs into a more useable format.
  29.  
  30.   Xevious has three 256x4 palette PROMs (one per gun) and four 512x4 lookup
  31.   table PROMs (two for sprites, two for background tiles; foreground
  32.   characters map directly to a palette color without using a PROM).
  33.   The palette PROMs are connected to the RGB output this way:
  34.  
  35.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  36.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  37.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  38.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  39.  
  40. ***************************************************************************/
  41. void xevious_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  42. {
  43.     int i;
  44.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  45.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  46.  
  47.  
  48.     for (i = 0;i < 128;i++)
  49.     {
  50.         int bit0,bit1,bit2,bit3;
  51.  
  52.  
  53.         /* red component */
  54.         bit0 = (color_prom[0] >> 0) & 0x01;
  55.         bit1 = (color_prom[0] >> 1) & 0x01;
  56.         bit2 = (color_prom[0] >> 2) & 0x01;
  57.         bit3 = (color_prom[0] >> 3) & 0x01;
  58.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  59.         /* green component */
  60.         bit0 = (color_prom[256] >> 0) & 0x01;
  61.         bit1 = (color_prom[256] >> 1) & 0x01;
  62.         bit2 = (color_prom[256] >> 2) & 0x01;
  63.         bit3 = (color_prom[256] >> 3) & 0x01;
  64.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  65.         /* blue component */
  66.         bit0 = (color_prom[2*256] >> 0) & 0x01;
  67.         bit1 = (color_prom[2*256] >> 1) & 0x01;
  68.         bit2 = (color_prom[2*256] >> 2) & 0x01;
  69.         bit3 = (color_prom[2*256] >> 3) & 0x01;
  70.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  71.  
  72.         color_prom++;
  73.     }
  74.  
  75.     /* color 0x80 is used by sprites to mark transparency */
  76.     *(palette++) = 0;
  77.     *(palette++) = 0;
  78.     *(palette++) = 0;
  79.  
  80.     color_prom += 128;  /* the bottom part of the PROM is unused */
  81.     color_prom += 2*256;
  82.     /* color_prom now points to the beginning of the lookup table */
  83.  
  84.     /* background tiles */
  85.     for (i = 0;i < TOTAL_COLORS(1);i++)
  86.     {
  87.         COLOR(1,i) = (color_prom[0] & 0x0f) | ((color_prom[TOTAL_COLORS(1)] & 0x0f) << 4);
  88.  
  89.         color_prom++;
  90.     }
  91.     color_prom += TOTAL_COLORS(1);
  92.  
  93.     /* sprites */
  94.     for (i = 0;i < TOTAL_COLORS(2);i++)
  95.     {
  96.         int c = (color_prom[0] & 0x0f) | ((color_prom[TOTAL_COLORS(2)] & 0x0f) << 4);
  97.  
  98.         if (c & 0x80) COLOR(2,i) = c & 0x7f;
  99.         else COLOR(2,i) = 0x80; /* transparent */
  100.  
  101.         color_prom++;
  102.     }
  103.     color_prom += TOTAL_COLORS(2);
  104.  
  105.     /* foreground characters */
  106.     for (i = 0;i < TOTAL_COLORS(0);i++)
  107.     {
  108.         if (i % 2 == 0) COLOR(0,i) = 0x80;  /* transparent */
  109.         else COLOR(0,i) = i / 2;
  110.     }
  111. }
  112.  
  113.  
  114.  
  115. /***************************************************************************
  116.  
  117.   Callbacks for the TileMap code
  118.  
  119. ***************************************************************************/
  120.  
  121. static void get_fg_tile_info(int tile_index)
  122. {
  123.     unsigned char attr = xevious_fg_colorram[tile_index];
  124.     SET_TILE_INFO(0,xevious_fg_videoram[tile_index],
  125.             ((attr & 0x03) << 4) | ((attr & 0x3c) >> 2))
  126.     tile_info.flags = TILE_FLIPYX((attr & 0xc0) >> 6);
  127. }
  128.  
  129. static void get_bg_tile_info(int tile_index)
  130. {
  131.     unsigned char code = xevious_bg_videoram[tile_index];
  132.     unsigned char attr = xevious_bg_colorram[tile_index];
  133.     SET_TILE_INFO(1,code + ((attr & 0x01) << 8),
  134.             ((attr & 0x3c) >> 2) | ((code & 0x80) >> 3) | ((attr & 0x03) << 5))
  135.     tile_info.flags = TILE_FLIPYX((attr & 0xc0) >> 6);
  136. }
  137.  
  138.  
  139.  
  140. /***************************************************************************
  141.  
  142.   Start the video hardware emulation.
  143.  
  144. ***************************************************************************/
  145.  
  146. int xevious_vh_start(void)
  147. {
  148.     bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,     8,8,64,32);
  149.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,64,32);
  150.  
  151.     if (!bg_tilemap || !fg_tilemap)
  152.         return 1;
  153.  
  154.     fg_tilemap->transparent_pen = 0;
  155.  
  156.     return 0;
  157. }
  158.  
  159.  
  160.  
  161. /***************************************************************************
  162.  
  163.   Memory handlers
  164.  
  165. ***************************************************************************/
  166.  
  167. WRITE_HANDLER( xevious_fg_videoram_w )
  168. {
  169.     if (xevious_fg_videoram[offset] != data)
  170.     {
  171.         xevious_fg_videoram[offset] = data;
  172.         tilemap_mark_tile_dirty(fg_tilemap,offset);
  173.     }
  174. }
  175.  
  176. WRITE_HANDLER( xevious_fg_colorram_w )
  177. {
  178.     if (xevious_fg_colorram[offset] != data)
  179.     {
  180.         xevious_fg_colorram[offset] = data;
  181.         tilemap_mark_tile_dirty(fg_tilemap,offset);
  182.     }
  183. }
  184.  
  185. WRITE_HANDLER( xevious_bg_videoram_w )
  186. {
  187.     if (xevious_bg_videoram[offset] != data)
  188.     {
  189.         xevious_bg_videoram[offset] = data;
  190.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  191.     }
  192. }
  193.  
  194. WRITE_HANDLER( xevious_bg_colorram_w )
  195. {
  196.     if (xevious_bg_colorram[offset] != data)
  197.     {
  198.         xevious_bg_colorram[offset] = data;
  199.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  200.     }
  201. }
  202.  
  203. WRITE_HANDLER( xevious_vh_latch_w )
  204. {
  205.     int reg;
  206.  
  207.     data = data + ((offset&0x01)<<8);   /* A0 -> D8 */
  208.     reg = (offset&0xf0)>>4;
  209.  
  210.     switch (reg)
  211.     {
  212.     case 0:
  213.         if (flipscreen)
  214.             tilemap_set_scrollx(bg_tilemap,0,data-312);
  215.         else
  216.             tilemap_set_scrollx(bg_tilemap,0,data+20);
  217.         break;
  218.     case 1:
  219.         tilemap_set_scrollx(fg_tilemap,0,data+32);
  220.         break;
  221.     case 2:
  222.         tilemap_set_scrolly(bg_tilemap,0,data+16);
  223.         break;
  224.     case 3:
  225.         tilemap_set_scrolly(fg_tilemap,0,data+18);
  226.         break;
  227.     case 7:     /* DISPLAY XY FLIP ?? */
  228.         flipscreen = data & 1;
  229.         tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  230.         break;
  231.    default:
  232.            logerror("CRTC WRITE REG: %x  Data: %03x\n",reg, data);
  233.            break;
  234.     }
  235. }
  236.  
  237.  
  238.  
  239.  
  240. /*
  241. background pattern data
  242.  
  243. colorram mapping
  244. b000-bfff background attribute
  245.           bit 0-1 COL:palette set select
  246.           bit 2-5 AN :color select
  247.           bit 6   AFF:Y flip
  248.           bit 7   PFF:X flip
  249. c000-cfff background pattern name
  250.           bit 0-7 PP0-7
  251.  
  252. seet 8A
  253.                                         2      +-------+
  254. COL0,1 --------------------------------------->|backg. |
  255.                                         1      |color  |
  256. PP7------------------------------------------->|replace|
  257.                                         4      | ROM   |  6
  258. AN0-3 ---------------------------------------->|  4H   |-----> color code 6 bit
  259.         1  +-----------+      +--------+       |  4F   |
  260. COL0  ---->|B8   ROM 3C| 16   |custom  |  2    |       |
  261.         8  |           |----->|shifter |------>|       |
  262. PP0-7 ---->|B0-7 ROM 3D|      |16->2*8 |       |       |
  263.            +-----------+      +--------+       +-------+
  264.  
  265. font rom controller
  266.        1  +--------+     +--------+
  267. ANF   --->| ROM    |  8  |shift   |  1
  268.        8  | 3B     |---->|reg     |-----> font data
  269. PP0-7 --->|        |     |8->1*8  |
  270.           +--------+     +--------+
  271.  
  272. font color ( not use color map )
  273.         2  |
  274. COL0-1 --->|  color code 6 bit
  275.         4  |
  276. AN0-3  --->|
  277.  
  278. sprite
  279.  
  280. ROM 3M,3L color reprace table for sprite
  281.  
  282.  
  283.  
  284. */
  285.  
  286.  
  287.  
  288.  
  289. /***************************************************************************
  290.  
  291.   Display refresh
  292.  
  293. ***************************************************************************/
  294.  
  295. static void draw_sprites(struct osd_bitmap *bitmap)
  296. {
  297.     int offs,sx,sy;
  298.  
  299.  
  300.     for (offs = 0;offs < spriteram_size;offs += 2)
  301.     {
  302.         if ((spriteram[offs + 1] & 0x40) == 0)  /* I'm not sure about this one */
  303.         {
  304.             int bank,code,color,flipx,flipy;
  305.  
  306.  
  307.             if (spriteram_3[offs] & 0x80)
  308.             {
  309.                 bank = 4;
  310.                 code = spriteram[offs] & 0x3f;
  311.             }
  312.             else
  313.             {
  314.                 bank = 2 + ((spriteram[offs] & 0x80) >> 7);
  315.                 code = spriteram[offs] & 0x7f;
  316.             }
  317.  
  318.             color = spriteram[offs + 1] & 0x7f;
  319.             flipx = spriteram_3[offs] & 4;
  320.             flipy = spriteram_3[offs] & 8;
  321.             if (flipscreen)
  322.             {
  323.                 flipx = !flipx;
  324.                 flipy = !flipy;
  325.             }
  326.             sx = spriteram_2[offs + 1] - 40 + 0x100*(spriteram_3[offs + 1] & 1);
  327.             sy = 28*8-spriteram_2[offs]-1;
  328.             if (spriteram_3[offs] & 2)  /* double height (?) */
  329.             {
  330.                 if (spriteram_3[offs] & 1)  /* double width, double height */
  331.                 {
  332.                     code &= 0x7c;
  333.                     drawgfx(bitmap,Machine->gfx[bank],
  334.                             code+3,color,flipx,flipy,
  335.                             flipx ? sx : sx+16,flipy ? sy-16 : sy,
  336.                             &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  337.                     drawgfx(bitmap,Machine->gfx[bank],
  338.                             code+1,color,flipx,flipy,
  339.                             flipx ? sx : sx+16,flipy ? sy : sy-16,
  340.                             &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  341.                 }
  342.                 code &= 0x7d;
  343.                 drawgfx(bitmap,Machine->gfx[bank],
  344.                         code+2,color,flipx,flipy,
  345.                         flipx ? sx+16 : sx,flipy ? sy-16 : sy,
  346.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  347.                 drawgfx(bitmap,Machine->gfx[bank],
  348.                         code,color,flipx,flipy,
  349.                         flipx ? sx+16 : sx,flipy ? sy : sy-16,
  350.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  351.             }
  352.             else if (spriteram_3[offs] & 1) /* double width */
  353.             {
  354.                 code &= 0x7e;
  355.                 drawgfx(bitmap,Machine->gfx[bank],
  356.                         code,color,flipx,flipy,
  357.                         flipx ? sx+16 : sx,flipy ? sy-16 : sy,
  358.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  359.                 drawgfx(bitmap,Machine->gfx[bank],
  360.                         code+1,color,flipx,flipy,
  361.                         flipx ? sx : sx+16,flipy ? sy-16 : sy,
  362.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  363.             }
  364.             else    /* normal */
  365.             {
  366.                 drawgfx(bitmap,Machine->gfx[bank],
  367.                         code,color,flipx,flipy,sx,sy,
  368.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0x80);
  369.             }
  370.         }
  371.     }
  372. }
  373.  
  374.  
  375. void xevious_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  376. {
  377.     tilemap_update(ALL_TILEMAPS);
  378.  
  379.     tilemap_render(ALL_TILEMAPS);
  380.  
  381.     tilemap_draw(bitmap,bg_tilemap,0);
  382.     draw_sprites(bitmap);
  383.     tilemap_draw(bitmap,fg_tilemap,0);
  384. }
  385.